// pages/classify/classify.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isFocus: false,
    shopId: '',
    firData: '',
    firId: '',
    firName: '',
    id:'',
    secData: '',
    secId: '',
    thingName: '',
    isMine: '',
    bottabDatadetail: app.globalData.bottabForPpsjindex,
    loadSuccess: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.showLoading()
    this.setData({
      isMine: options.isMine,
      shopId: options.shopId,
      area: options.area,
      id: options.id,
      ['bottabDatadetail[1].current']: true
    })
    this.getFirType(true)
  },
  getFirType: function (tag) {
    var _this = this;
    wx.request({
      url: app.globalData.httpApiCar + 'shopInfo/showShopThingTypes',
      data: {
        shopId: _this.data.shopId  //889
      },
      method:'POST',
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 默认值
      },
      success: function (res) {
        _this.setData({
          loadSuccess: true
        })
        wx.hideLoading()
        if (res.data.success) {
          if (res.data.data.types.length > 0){
            if(tag){
              _this.setData({
                firId: res.data.data.types[0].id,
                firName: res.data.data.types[0].value
              })
            }
            _this.setData({
              firData: res.data.data.types
            })
            _this.getSecType();
          }
        }
      }
    })
  },
  firTapFunc: function(e){
    var item = e.currentTarget.dataset.item;
    console.info(item)
    this.setData({
      firId: item.id,
      firName: item.value
    })
    this.getSecType();
  },
  getSecType: function () {
    var _this = this;
    wx.request({
      url: app.globalData.httpApiCar + 'shopThing/queryShopThingsByType',
      data: {
        shopId: _this.data.shopId,  //889
        type: _this.data.firId,   // 9
        thingName: _this.data.thingName
      },
      success: function (res) {
        if (res.data.success) {
          for(var i = 0 ; i <  res.data.data.length; i++){
            res.data.data[i].realThingShowImg = res.data.data[i].realThingShowImg.split(",")[0]
          }
          _this.setData({
            secData: res.data.data
          })
        }
      }
    })
  },
  openDetail: function (e) {
    var area = e.currentTarget.dataset.area;
    wx.navigateTo({
      url: '/pages/wareDetail/wareDetail?id=' + e.currentTarget.dataset.id + '&isMine=' + this.data.isMine + '&shopId=' + this.data.shopId + '&area=' + this.data.area
    })
  },
  switchBotab(e) {
    wx.navigateTo({
      url: e.currentTarget.dataset.url + '?shopId=' + this.data.id + '&isMine=' + this.data.isMine + '&area=' + this.data.shopArea + '&id=' + this.data.id
    })
  },
  focusFunc: function () {
    this.setData({
      isFocus: true
    })
  },
  blurFunc: function (e) {
    if (!e.detail.value) {
      this.setData({
        isFocus: false
      })
    }
  },
  inputFunc: function (e) {
    this.setData({
      thingName: e.detail.value
    })
    this.getSecType()
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})